import 'dart:convert' show json;

import 'package:loxen/mode/user.dart';

class FollowerList {
  FollowerList({
    this.count,
    this.next,
    this.previous,
    this.results,
  });

  factory FollowerList.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<Follower> results =
    jsonRes['results'] is List ? <Follower>[] : null;
    if (results != null) {
      for (final dynamic item in jsonRes['results']) {
        if (item != null) {
          results.add(Follower.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }
    return FollowerList(
      count: asT<int>(jsonRes['count']),
      next: asT<String>(jsonRes['next']),
      previous: asT<String>(jsonRes['previous']),
      results: results,
    );
  }

  int count;
  String next;
  String previous;
  List<Follower> results;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'count': count,
    'next': next,
    'previous': previous,
    'results': results,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Follower {
  Follower({
    this.id,
    this.mutual_following,
    this.user,
  });

  factory Follower.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Follower(
    id: asT<int>(jsonRes['id']),
    mutual_following: asT<int>(jsonRes['mutual_following']),
    user: User.fromJson(asT<Map<String, dynamic>>(jsonRes['user'])),
  );

  int id;
  int mutual_following;
  User user;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'id': id,
    'mutual_following': mutual_following,
    'user': user,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

